<?php

class SystemController extends Controller {

    public function actionIndex() {
        $this->pageTitle = Yii::t('app', 'System config');

        $systemModel = System::model()->findAll('del_flg=0');

        if (isset($_POST) && $_POST) {
            $check = false;
            foreach($systemModel as $value){
                if(isset($_POST[$value->name]) && $_POST[$value->name]!=''){
                    $result = System::updateValue($value->name, $_POST[$value->name]);
                    if($result){
                        $check = true;
                    }else{
                        $check = false;
                        break;
                    }
                }
            }
            if($check){
                Yii::app()->user->setFlash('success', Yii::t('app', 'Updated success!'));
                $this->redirect(array('system/index'));
            }else{
                Yii::app()->user->setFlash('error', Yii::t('app', 'Update false!'));
            }
        }

        $this->render('index', array(
            'systemModel' => $systemModel,
        ));
    }
}